load("BCHAI.mat");
CA1 =zeros(1,32);
CA2 = zeros(1,16);
CA3 = zeros(1,8);
CA4 = zeros(1,4);
CA5 = zeros(1,2);
CD1 =zeros(1,32);
CD2 = zeros(1,16);
CD3 = zeros(1,8);
CD4 = zeros(1,4);
CD5 = zeros(1,2);

for i = 100:100
s = ACHAI(i:i+63);
Len = length(s);
[CA1(i,:), CD1(i,:)] = dwt(s, 'db1'); % 采用db1小波基分解
% a1 = upcoef('a', ca1, 'db1', 1, Len); % 从系数得到细节信号
% d1 = upcoef('d', cd1, 'db1', 1, Len); % 从系数得到细节信号
% s1 = a1+d1; % 重构信号
[CA2(i,:), CD2(i,:)] = dwt(CA1(i,:),'db1');
[CA3(i,:), CD3(i,:)] = dwt(CA2(i,:),'db1');
[CA4(i,:), CD4(i,:)] = dwt(CA3(i,:),'db1');
[CA5(i,:), CD5(i,:)] = dwt(CA4(i,:),'db1');


figure;
subplot(2, 4, 1); plot(CA1(i,:),LineWidth=1); title('A1');
subplot(2, 4, 5); plot(CD1(i,:),LineWidth=1); title('D1');

subplot(2, 4, 2); plot(CA2(i,:),LineWidth=1); title('A2');
subplot(2, 4, 6); plot(CD2(i,:),LineWidth=1); title('D2');

subplot(2, 4, 3); plot(CA3(i,:),LineWidth=1); title('A3');
subplot(2, 4, 7); plot(CD3(i,:),LineWidth=1); title('D3');

subplot(2, 4, 4); plot(CA4(i,:),LineWidth=1); title('A4');
subplot(2, 4, 8); plot(CD4(i,:),LineWidth=1); title('D4');

%subplot(2, 2, 1); plot(CA5(i,:)); title('ca5 低频');
%subplot(2, 2, 2); plot(CD5(i,:)); title('cd5 高频');

end




CA = [CA1,CA2,CA3,CA4,CA5];
CD = [CD1,CD2,CD3,CD4,CD5];

%%

% figure;
% subplot(2, 2, 1); plot(s); title('初始电源信号');
% subplot(2, 2, 2); plot(ca1); title('一层小波分解的低频信息');
% disp(length(ca1))
% subplot(2, 2, 3); plot(cd1); title('一层小波分解的高频信息');
% subplot(2, 2, 4); plot(s1, 'r-'); title('一层小波分解的重构信号');
% 
% figure(2);
% subplot(2, 1, 1); plot(a1); title('从系数a得到近似信号');
% subplot(2, 1, 2); plot(d1); title('一d1近似信号');
% 
% figure(3);
% [ca2,cd2] = dwt(ca1,'db1');
